package com.ruoyi.novel.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.novel.domain.Vip;
import com.ruoyi.novel.service.IVipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员商品Controller
 *
 * @author 张三
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/novel/vip")
public class VipController extends BaseController
{
    @Autowired
    private IVipService vipService;

    /**
     * 查询会员商品列表
     */
    @PreAuthorize("@ss.hasPermi('novel:vip:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vip vip)
    {
        startPage();
        List<Vip> list = vipService.selectVipList(vip);
        return getDataTable(list);
    }

    /**
     * 导出会员商品列表
     */
    @PreAuthorize("@ss.hasPermi('novel:vip:export')")
    @Log(title = "会员商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vip vip)
    {
        List<Vip> list = vipService.selectVipList(vip);
        ExcelUtil<Vip> util = new ExcelUtil<Vip>(Vip.class);
        util.exportExcel(response, list, "会员商品数据");
    }

    /**
     * 获取会员商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('novel:vip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(vipService.selectVipById(id));
    }

    /**
     * 新增会员商品
     */
    @PreAuthorize("@ss.hasPermi('novel:vip:add')")
    @Log(title = "会员商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vip vip)
    {
        return toAjax(vipService.insertVip(vip));
    }

    /**
     * 修改会员商品
     */
    @PreAuthorize("@ss.hasPermi('novel:vip:edit')")
    @Log(title = "会员商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vip vip)
    {
        return toAjax(vipService.updateVip(vip));
    }

    /**
     * 删除会员商品
     */
    @PreAuthorize("@ss.hasPermi('novel:vip:remove')")
    @Log(title = "会员商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(vipService.deleteVipByIds(ids));
    }
}
